package org.geeks.gscaffeine.func;

import com.github.benmanes.caffeine.cache.Cache;
import com.github.benmanes.caffeine.cache.Caffeine;
import com.github.benmanes.caffeine.cache.RemovalCause;
import lombok.extern.slf4j.Slf4j;
import org.junit.Test;

@Slf4j
public class CaffeineRemovalT {

  @Test
  public void listeners() throws Exception {
    Cache<String, String> cache =
        Caffeine.newBuilder()
            .removalListener(
                (String k, String v, RemovalCause cause) ->
                    log.info("Key {} was removed {}", k, cause))
            .build();

    String key = "Geek-S";

    cache.put(key, "Hello, world");

    cache.invalidate(key);

    String value = cache.getIfPresent("Hello");

    log.info("Value is {}", value);
  }
}
